package com.rt.easyjava.common.base;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import java.io.Serializable;
import java.util.Date;

/**
 * Created by wxy on 22/01/09.
 */
@Data
@ToString
@EqualsAndHashCode(callSuper = false)
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "分页传输对象")
public class BaseV3Dto extends PageDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    private Long creatorId;
    private String creator;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    private Long updatorId;
    private String updator;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    private Long companyId;
    @ApiModelProperty(hidden = true)
    private Object deleteFlag; // 枚举，通过dozer转换:  当bean->dto时, 放入json对象 如{'id':1, 'name':'无效'}； 当dto->bean时, object->Integer
    private Integer version;

    //----------------------------------------
    // 与页面交互时的参数
    //----------------------------------------
    private String createTime_Start;
    private String createTime_End;
    private String updateTime_Start;
    private String updateTime_End;

    public void setCreatorUpdatorInfo(String userDetailsJson) {
        UserDetailsDto userDetailsDto = UserDetailsDto.getUserDetailsDto(userDetailsJson, "");
        this.setCreatorId(Long.parseLong(userDetailsDto.getUserId()));
        this.setCreator(userDetailsDto.getUserName());
        this.setUpdatorId(Long.parseLong(userDetailsDto.getUserId()));
        this.setUpdator(userDetailsDto.getUserName());
        this.setCompanyId(Long.parseLong(userDetailsDto.getCompanyId()));
        this.setCreateTime(null);
        this.setUpdateTime(null);
    }
    public void setUpdatorInfo(String userDetailsJson) {
        UserDetailsDto userDetailsDto = UserDetailsDto.getUserDetailsDto(userDetailsJson, "");
        this.setUpdatorId(Long.parseLong(userDetailsDto.getUserId()));
        this.setUpdator(userDetailsDto.getUserName());
        this.setCreatorId(null);
        this.setCreator(null);
        this.setCompanyId(null);
        this.setCreateTime(null);
        this.setUpdateTime(null);
    }

}
